package customer;

import java.sql.PreparedStatement;
import java.text.SimpleDateFormat;
import java.util.Date;

import connection.MyConnection;

public class CustomerDeposit {
	
	private int id;
	private  String phone;
	private double remainamount;
	private double deposit;
	
	//private  double newremainamount = remainamount - deposit;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public double getRemainamount() {
		return remainamount;
	}
	public void setRemainamount(double remainamount) {
		this.remainamount = remainamount;
	}
	public double getDeposit() {
		return deposit;
	}
	public void setDeposit(double deposit) {
		this.deposit = deposit;
	}
/*	public double getNewremainamount() {
		return newremainamount;
	}
	public void setNewremainamount(double newremainamount) {
		this.newremainamount = newremainamount;
	}*/
	
	
	
	public String execute() throws Exception
	{
		MyConnection mc = new MyConnection();
		mc.connect();
		Date d = new Date();
		SimpleDateFormat df = new SimpleDateFormat("dd//MM//yyyy");
		String date = df.format(d).toString();
		
		try
		{
			PreparedStatement ps = mc.con.prepareStatement("insert into deposit (phone, deposit_amount, date, c_id) values(?,?,?,?)");
			ps.setString(1, phone);
			ps.setDouble(2, deposit);
			ps.setString(3, date);
			ps.setInt(4, id);
			ps.executeUpdate();
			
			PreparedStatement ps1 = mc.con.prepareStatement("update customer set remaining_payment = ? where id = ? ");
			remainamount=remainamount-deposit;
			ps1.setDouble(1, remainamount);
			ps1.setInt(2, id);
			ps1.executeUpdate();
		}
		
		catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
		
		
		return "success";
	}

}
